const axios=require("axios").default
const cheerio=require("cheerio")

const mood=require("../models/mood")


async function getBookDetail(dedailUrl) {
    const resp = await axios.get(dedailUrl)
    const $ = cheerio.load(resp.data)
    let str=[]
    for(var i=0;i<$(".moodlist section").length;i++){
    const sculpture=$(".mood_tx img").eq(i).attr("src")
    const text=$(".moodtext").eq(`${i}`).text()
    const img=$(`.mood_pic_c i img:eq(${i})`).attr("src")||"d/file/p/2022/01-13/10650d6bc3739e8336a3a6c588d68ad7.jpg"
    const time=$(`.moodtime`).eq(i).text()
    str.push(
        {   
            name:"Han Yu",
            sculpture:"http://localhost:3300/images/tx.jpeg",
            text:text,
            time:time,
            img:"https://www.tjcblog.com"+img,
            data:time,
        }
        )
    }
    return str
}

getBookDetail("https://www.tjcblog.com/mood/index.html").then(data=>{
    console.log(data)
    mood.bulkCreate(data)
})
